package com.wie.mapper;

import com.wie.pojo.Article;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Mapper
public interface ArticleMapper {
    /**
     * 新增文章
     * @param article
     */
    @Insert("insert into article(title, content, cover_img, state, category_id, create_user, create_time, update_time) " +
            "VALUES(#{title}, #{content}, #{coverImg}, #{state}, #{categoryId}, #{createUser}, #{createTime}, #{updateTime}) ")
    void add(Article article);

    /**
     * 查询文章列表并根据条件分页
     * @param userId
     * @param categoryId
     * @param state
     * @return
     */
    List<Article> list(@Param("userId") Integer userId, @Param("categoryId") Integer categoryId, @Param("state") String state);

    /**
     * 更新文章
     */
    void update(Article article);

    /**
     * 根据文章id获取文章详情
     * @param id
     * @return
     */
    @Select("select * from article where id = #{id}")
    Article getArticleById(Integer id);

    @Delete("delete from article where id = #{id}")
    void deleteById(Integer id);
}
